#include "../tools.h"
#include <climits>

// 中序遍历 - 是否有序
class Solution {
public:
    bool res = true;
    bool trace(TreeNode* root, long long lower, long long upper){
        if(root == nullptr) return true;
        if(root->val <= lower || root->val >= upper) {
            return false;
        }

        return trace(root->left, lower, root->val) && trace(root->right, root->val, upper);
    }
    bool isValidBST(TreeNode* root) {
        if(root == nullptr) return true;
        return trace(root, LONG_MIN, LONG_MAX);
    }
};


int main(int argc, char const *argv[])
{
    Solution sol;

    vector<int> vec = {2,1,3};
    TreeNode* tree = create_tree(vec);
    show(tree);

    cout << sol.isValidBST(tree);


    return 0;
}
